define(['app/module/user/user.js','wrapper','cache'],function(user,wrapper,cache){

/*
 * 加载jqery包装生成的组件
 */

	wrapper.wrap('loading', "<div></div>",function(vm,el){
		var target = $(el);
		if(target.hasClass('loading'))	return;
		
		$(el).loadingOverlay();
 	});

//定义主vm
 	var model = avalon.define({
                $id: "content-main",
                initcomplete:false, //是否初始化完成
				isLogin : false,
				userName:"",
				passwd:"",
				errDesc:"",
				login:function(){
					var u = model.userName;
					var p = model.passwd;

					user.login(u,p,function(data){
					 	//avalon.log("u:",u,"p:",p);
					 	//avalon.log("login",data);
					 	if (data.returnCode === "0"){
						 	//if(data.data.result === "0"){
						 		//加载页面
						 		require([ "app/module/nav/headNav.js","app/module/menuView/menuView.js","app/module/nav/contentNav.js"], function(head,nav,view) {

						 			model.isLogin = true;
						 			model.initcomplete = true;
								});
						 	}else{
						 		model.errDesc="用户名、密码错误"
						 		model.initcomplete = true;
						 	}
					 	//}
					 });
				},
				init:function(){
					
					//if(sessionStorage.getItem("userInfo") != null){
					//兼容性处理引入cache.js
					if(cache.go("signature") != null){	
						 require([ "app/module/nav/headNav.js","app/module/menuView/menuView.js","app/module/nav/contentNav.js"], function(head,nav,view) {
							model.isLogin = true;
							model.initcomplete = true;					
							}	
						);
					}else{
						model.isLogin = false;
						model.initcomplete = true;
					}
	
				}
	});
//使用空用户登陆一次，如果用户已经后端后返回登陆成功
 model.init();


 return model;
});